class Solution {
public:
    string reverseOnlyLetters(string s) {
        int n = s.size();
        string cp;
        for(int i = 0; i < n; ++i)
        {
            if(isalpha(s[i]))
                cp += s[i];
        }
        int pos = cp.size() - 1;
        for(int i = 0; i < n; ++i)
        {
            if(isalpha(s[i]))
                s[i] = cp[pos--];
        }
        return s;
    }
};
